<!DOCTYPE html>
<head>
  <#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
  <meta charset="utf-8">
  <title>创建任务计划</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/forms/currencyCss.css">
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/public/ztree/zTreeStyle.css"/>
  <script src="${ctx}/qbdmsStatic/public/ztree/jquery.min.js"></script>
  <script src="${ctx}/qbdmsStatic/public/ztree/jquery.ztree.all.min.js"></script>
  <script type="text/javascript">
    var __ctx = "${ctx}";
  </script>
  <style>
    .qbdms-TBinformation {
      margin-left: 0;
      font-size: 15px
    }

    .treeFormPreview {
      bottom: 42px;
    }
  </style>
</head>
<body class="listBody">
<div class="qbdms-bodyDiv">
  <div class="qbdms-backDiv">
    <div class="layui-table-view-body" style="padding: 0 24px 24px;">
      <div class="qbdms-formTitle" style="border-bottom: 1px solid #E5F0FF">创建任务计划
      <#if flag!='1'>  <i class="qbdms-returnOn closeWindow">返回</i></#if></div>
      <form class="layui-form treeFormPreview" requrl="${ctx}/qbdms/wQbdFalProblemreset/getPlan"
            lay-filter="wQbdFalProblemPlanDataForm" id="wQbdFalProblemPlanDataForm">
        <div class="layui-row">
          <div class="" style="width: 45%;display: none">
            <label class="layui-form-label qbdms-label" title="id">id</label>
            <div class="layui-input-block qbdms-input">
              <input type="hidden" placeholder="请输入" autocomplete="off"
                     class="layui-input textInput" name="id" maxlength="50">
            </div>
          </div>
          <div class="" style="width: 45%;display: none">
            <label class="layui-form-label qbdms-label" title="problemId">problemId</label>
            <div class="layui-input-block qbdms-input">
              <input type="hidden" placeholder="请输入" autocomplete="off"
                     class="layui-input textInput" name="problemId" maxlength="50" value="${id}">
            </div>
          </div>
          <div class="" style="width: 45%">
            <label class="layui-form-label qbdms-label" title="措施内容">措施内容<span style="color: red;">*</span></label>
            <div class="layui-input-block qbdms-input">
              <input type="text" placeholder="请输入" autocomplete="off" class="layui-input textInput"
                     name="content" maxlength="30" lay-verify="required" lay-reqtext="措施内容是必填项" id="content">
            </div>
          </div>
          <div class="" style="width: 45%">
            <label class="layui-form-label qbdms-label" title="计划完成时间">计划完成时间<span style="color: red;">*</span></label>
            <div class="layui-input-block qbdms-input">
              <input type="text" placeholder="请选择" autocomplete="off"
                     class="layui-input dateTimeFiled input-right time-init" name="planEndTime"
                     maxlength="7" lay-verify="required" lay-reqtext="计划完成时间是必填项" readonly id="planEndTime">
            </div>
          </div>
          <div class="" style="width: 45%">
            <label class="layui-form-label qbdms-label" title="责任人">责任人<span style="color: red;">*</span></label>
            <button type="button" class="layui-btn qbdms-twoBtn selectorBtn" typeid="4" style="float: right" id="user">选择</button>
            <div class="layui-input-block qbdms-input qbdms-inputIsButton">
              <input type="text" name="userName" placeholder="请选择"
                     autocomplete="off" class="layui-input  selectorInput"
                     maxlength="500" fieldname="userName" readonly>
              <input type="hidden" name="userId" placeholder="请输入责任人ID"
                     autocomplete="off" class="layui-input  textInput getIds"
                     fieldname="userId">
            </div>
          </div>
          <#if isInclude=='true'>
          <#include "/wQbdFalProblemreset/planTwo.html">
        </#if>
        </div>
    <input type="hidden" name="flowStatus">
        <div class="layui-form-item" style="margin-top: 48px">
          <p style="text-align: left;margin-left: 145px;">
            <span id="hideAndShow" style="display: none;">
                <a lay-submit lay-filter="wQbdFalProblemPlan" class="layui-btn btn-n privateSubmit qbdms-oneBtn" requrl="${ctx}/qbdms/wQbdFalProblemreset/savePlan" id="urlFormSave">保存</a>
                <#if flowStatus=='0'><a lay-filter="wProblemresetMsg" id="run" class="layui-btn btn-n qbdms-oneBtn">启动</a></#if>
                <button type="reset" id="closeWindow" style="margin-left: 10px;" class="layui-btn layui-btn-sm btn-save qbdms-oneBtnLine">取消</button>
            </span>
          </p>
        </div>
      </form>
    </div>
  </div>
</div>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    var runFlag=false ;
    var vaildFlag ;
    var flowStatus="${flowStatus}";
  layui.config({
    base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'setter', 'layer', 'propsHandle', 'upload', 'common', 'laydate', 'jquery', 'publicMethods', 'qbdmsForm','form'], function () {
    var $ = layui.jquery,
        laydate = layui.laydate,
        setter = layui.setter,  // 配置信息
        layer = layui.layer,
        common = layui.common,
        propsHandle = layui.propsHandle,
        upload = layui.upload,
        publicMethods = layui.publicMethods,
        formId = '' || '',
        defProps = {
          //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
          viewMould: 'moulds/', // 组件模块 存放文件 *****
          initCss: [
            'style/currencyCss'
          ],
          // formAreaInfo:'.formPreview',
          formAreaInfo: 'html',
          temDate: '.temDate',
          uploadFileBtn: '.uploadFileBtn',
          uploadImgBtn: '.uploadImgBtn',
          richTextArea: '.richTextArea',
          selectInput: '.selectInput',
          radioOptionCont: '.radioOptionCont',
          dataLexiTree: '.dataLexiTree',
          selectorBtn: '.selectorBtn',
        },
        temQuery = new propsHandle(),  // 实例化模板功能部分
        form = layui.qbdmsForm;
    // 初始化模板功能
    temQuery.initTem({
      selectorBtn: defProps.selectorBtn,
      selectorTemPath: setter.views + defProps.viewMould
    });
    $(".subContTem").hide();
    $(".qbdms-SubTableTitle").hide();
    $(".qbdms-tableDiv").hide();
    var dateTimeFiledLen = $(".dateTimeFiled");
    for (var i = 0; i < dateTimeFiledLen.length; i++) {
      laydate.render({
        elem: dateTimeFiledLen[i] //指定元素
        , type: 'date'
        , trigger: 'click'
      });
    }

      vaildFlag = false;
      $("#urlFormSave").click(function () {
        //- 附件密级不能高于表单密级 开始 ------------------------------------------------------
        var selectMaxVal = 0;
        var formSecretVal = "${secret}";
        $(".fileSecLevel select").each(function () {
          selectMaxVal = selectMaxVal >= $(this).val() ? selectMaxVal : $(this).val();
        });

        if (selectMaxVal > formSecretVal) {
          layer.msg('附件密级不能高于表单密级。', {icon: 5});
          vaildFlag =false;
          return false;
        }
          vaildFlag=form.VerifyForm("wQbdFalProblemPlanDataForm");
      });

    //关闭当前页面
    $("#closeWindow,.closeWindow").click(function () {
      window.location.href = '${ctx}/qbdms/wQbdFalProblemreset/view/list';
    });

    if("${flag}"!="1"){
      $("#hideAndShow").show();
    }
    var common = layui.common;
    var index = parent.layer.getFrameIndex(window.name);
    common.updateForm({
      name: 'wQbdFalProblemPlanDataForm',
      idValue: "${id}",
      primary: "id",
      beforeSubmitFun: function (data) {
        if("${isInclude}"=="true") {

          //- 附件密级不能高于表单密级 开始 ------------------------------------------------------
          var selectMaxVal = 0;
          var formSecretVal = "${secret}";
          $(".fileSecLevel select").each(function () {
            selectMaxVal = selectMaxVal >= $(this).val() ? selectMaxVal : $(this).val();
          });

          if (selectMaxVal > formSecretVal) {
            layer.msg('附件密级不能高于表单密级。', {icon: 5});
            return false;
          }
          //- 附件密级不能高于表单密级 结束 ------------------------------------------------------
          $(".uploadFileList").each(function (i, v) {
            common.constructFileStr(v)
          });
          var files = [];
          //整理上传附件的隐藏域，将提交的字符串转为json对象
          $(".uploadInput").each(function () {
            var uploadName = $(this).attr("name");
            if (!$(this).val()) {
              return;
            }
            data.field[uploadName] = eval($(this).val());
            files = files.concat(eval($(this).val()));
          });
          // 控制文件密级
          return common.setFileLevel(files);
        }
      },
      getCallback: function (data) {
        $("#content").attr("disabled",true);
        $("#planEndTime").attr("disabled",true);
        $("#userId").attr("disabled",true);
        $("input[name='userName']").attr("ids", data.data.userId);
        if(null!=data.data.userId&&""!=data.data.userId){
          $("#user").hide();
        }
        if("${rolAlias}"=="bpm_xhzgzly"||data.data.flowStatus=='0'){
          $("#user").show();
          $("#content").attr("disabled",false);
          $("#planEndTime").attr("disabled",false);
          $("#userId").attr("disabled",false);
        }
        if("${isInclude}"=="true") {
          $('.uploadFileList').each(function () {
            var fileUploadName = $(this).attr("fileUploadName");
            var jsonFile = data.data[fileUploadName];
            var files = eval(jsonFile);

            if (files) {
              for (var i = 0; i < files.length; i++) {
                var fileLevel = files[i].fileLevel;
                var fileLevelText = files[i].fileLevelText;
                var fileSec = '<div class="fileSecLevel layui-input-inline">'
                    + '<@secSelect.sec_select data_src=1 hasBlank=false/>'
                    + "</div>";
                var newStr = '<span class="file-id" style="margin-right: 20px;" fileId='
                    + files[i].fileId + ' fileLevelText="' + fileLevelText + '">'
                    + fileSec
                    + '<span class="file-name" title="点击下载文件" onclick="downFile(this)"><i class="iconfont data-iconcommon_fujian" style="margin-right: 5px"></i>'
                    + files[i].fileName
                    + '</span><i class="iconfont data-iconcommon_close deleteFile" ></i></span>';
                $(this).append(newStr);
                $(this).find("select:last").val(fileLevel);
              }
            }
          });
        }
      },
      updateCallback: function (data) {
          if((flowStatus==0||flowStatus==""||null==flowStatus)&&runFlag==true){
              run(data.data.id);
          }
        if (publicMethods._filterRecord(data)) {
          if ($(".privateSubmit")) {
            $(".privateSubmit").attr("disabled", false).css("pointer-events", "auto");
          }
          if((flowStatus=="0" || flowStatus==null || flowStatus=="99"||flowStatus=="") && runFlag==false) {
              layer.alert(publicMethods.confirmStyle(data.msg), {title: false, skin: 'confirm-class'},
                  function (index) {
                      layer.close(index);
                      //关闭当前页面
                      window.location.href = '${ctx}/qbdms/wQbdFalProblemreset/view/list';
                  });
          }
          runFlag=false;
        } else {
          layer.alert(publicMethods.confirmStyle(data.msg), {title: false, skin: 'confirm-class'});
        }
        return false;
      }
    });
    var secSelect = '<@secSelect.sec_select data_src=1 hasBlank=false/>'
    common.uploadfun(".fileUpload", {
      acceptMime: 'application/pdf, ' +
          'application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      exts: "doc|docx|pdf",
      secSelect: secSelect,
      isSub: false,
      isMultiFile: true,
      upLoadNumber: 1
    });

      $("#run").click(function () {
          var flag=form.VerifyForm("wQbdFalProblemPlanDataForm");
          if(flag==false){
              return false;
          }
          runFlag=true;
          $("#urlFormSave").click();
      })
      function run(id) {
          var id = id;
          var problemId = $("input[name='problemId']").val();
          var userId = $("input[name='userId']").val();
          var content = $("input[name='content']").val();
          var planEndTime = $("input[name='planEndTime']").val();
          var userName = $("input[name='userName']").val();
          var situation = $("input[name='situation']").val();
          var material = $("input[name='material']").val();
          var flowStatus = $("input[name='flowStatus']").val();
          var nowData = {"id": id,"problemId": problemId,"userId": userId,"content": content,"planEndTime": planEndTime,"userName": userName,"situation": situation,"material": material,"flowStatus": flowStatus};
          $.ajax({
              url:"${ctx}/qbdms/wQbdFalProblemreset/runPlan",
              type: "post",
              dataType: 'json',
              contentType : 'application/json',
              data: JSON.stringify(nowData),
              success : function (data) {
                  if (common.filterRecord(data)) {
                      layer.alert(publicMethods.confirmStyle(data.msg), {title: false, skin: 'confirm-class'},
                          function (index) {
                              layer.close(index);
                              //关闭当前页面
                              window.location.href = '${ctx}/qbdms/wQbdFalProblemreset/view/list';
                          });
                  } else {
                      layer.alert(publicMethods.confirmStyle(data.msg), {title: false, skin: 'confirm-class'},
                          function (index) {
                              layer.close(index);
                              //关闭当前页面
                              window.location.href = '${ctx}/qbdms/wQbdFalProblemreset/view/list';
                          })
                  }
                  return false;
              },
              error : function (XMLHttpRequest, textStatus, errorThrown) {
                  layer.alert(publicMethods.confirmStyle("内容已保存，启动失败"), {title: false, skin: 'confirm-class'},
                      function (index) {
                          layer.close(index);
                          //关闭当前页面
                          window.location.href = '${ctx}/qbdms/wQbdFalProblemreset/view/list';
                      })
              }
          })
      }

    publicMethods.bottomFixd()
    form.on('select', function (data) {
      publicMethods.bottomFixd()
    });
    form.render();
  });
</script>
</body>
</html>